/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 * Description: 集合通信remote notify接口
 */

#include "remote_notify.h"
#include "remote_notify_impl.h"

namespace hccl {

RemoteNotify::RemoteNotify()
{
}

RemoteNotify::~RemoteNotify()
{
}

HcclResult RemoteNotify::Init(const std::vector<u8>& byteVector)
{
    pimpl_.reset((new (std::nothrow) RemoteNotifyImpl()));
    CHK_SMART_PTR_NULL(pimpl_);
    HcclResult ret = pimpl_->Init(byteVector);
    if (ret != HCCL_SUCCESS) {
        pimpl_ = nullptr;
        HCCL_ERROR("[RemoteNotify]Init failed, ret[%p]", ret);
        return ret;
    }

    return HCCL_SUCCESS;
}

HcclResult RemoteNotify::Init(const HcclSignalInfo &notifyInfo, const NotifyLoadType type)
{
    pimpl_.reset((new (std::nothrow) RemoteNotifyImpl()));
    CHK_SMART_PTR_NULL(pimpl_);
    HcclResult ret = pimpl_->Init(notifyInfo, type);
    if (ret != HCCL_SUCCESS) {
        pimpl_ = nullptr;
        HCCL_ERROR("[LocalNotify]Init failed, ret[%p]", ret);
        return ret;
    }
 
    notifyPtr = pimpl_->ptr();
    return HCCL_SUCCESS;
}

HcclResult RemoteNotify::Open()
{
    CHK_RET(pimpl_->Open());

    notifyPtr = pimpl_->ptr();

    return HCCL_SUCCESS;
}

HcclResult RemoteNotify::Close()
{
    if (pimpl_ != nullptr) {
        pimpl_->Close();
        pimpl_ = nullptr;
        notifyPtr = nullptr;
    }
    return HCCL_SUCCESS;
}

HcclResult RemoteNotify::Post(Stream& stream, HcclDispatcher dispatcher, s32 stage)
{
    CHK_SMART_PTR_NULL(pimpl_);
    return pimpl_->Post(stream, dispatcher, stage);
}

HcclResult RemoteNotify::GetNotifyData(HcclSignalInfo &notifyInfo)
{
    CHK_SMART_PTR_NULL(pimpl_);
    return pimpl_->GetNotifyData(notifyInfo);
}

HcclResult RemoteNotify::SetNotifyData(HcclSignalInfo &notifyInfo)
{
    CHK_SMART_PTR_NULL(pimpl_);
    return pimpl_->SetNotifyData(notifyInfo);
}

HcclResult RemoteNotify::GetNotifyOffset(u64 &notifyOffset)
{
    CHK_SMART_PTR_NULL(pimpl_);
    return pimpl_->GetNotifyOffset(notifyOffset);
}
}